package main

import (
	"Ljohn/mathTest/applyMath"
	"Ljohn/mathTest/sort"
	"Ljohn/mathTest/weightPolling"
	"fmt"
	"math"
	"math/big"
)

func main() {
	//sortTest()
	//wTest()
	tes1t()
}

func bracketMatchTest() {
	applyMath.CheckBracketTest()
}

func bigTest() {
	x := big.NewFloat(97)
	y := big.NewFloat(7)
	z := x.Quo(x, y)
	fmt.Println(z)
}

func floatTest() {
	var t1 float64 = 97
	var t2 float64 = 7
	fmt.Println(t1)

	fmt.Println(t2)
	fmt.Println(t1 / t2)
}

func test1() {
	lat1 := 30.542044
	lon1 := 104.060599

	//lat2 := 30.5396930000
	//lng2 := 104.0746500000

	lat3 := 30.5461790000
	lon3 := 104.0692120000

	fmt.Println(EarthDistance(lat1, lon1, lat3, lon3))
}

func EarthDistance(lat1, lon1, lat2, lon2 float64) float64 {
	var radius float64 = 6371000 // 6378137
	rad := math.Pi / 180.0

	lat1 = lat1 * rad
	lon1 = lon1 * rad
	lat2 = lat2 * rad
	lon2 = lon2 * rad

	theta := lon2 - lon1
	dist := math.Acos(math.Sin(lat1)*math.Sin(lat2) + math.Cos(lat1)*math.Cos(lat2)*math.Cos(theta))

	return dist * radius
}

func test(x float64) {
	if math.Pow(x, 5)+x == 1 {
		fmt.Println(x)
	}

	for i := 0; i < 1000; i++ {

	}
}

func sortTest() {
	insertTest()
}

func insertTest() {
	a := []int{6, 2, 3, 1, 7, 4, 5}
	sort.InsertionSort(a)
	fmt.Println(a)
}

func wTest() {
	weightPolling.TestWeightPolicy()
}

type visitor interface {
	fn(func(v visitor))
}

type t struct {
	name string
}

func (m *t) fn(f func(v visitor)) {
	f(m)
}

func tes1t() {
	var o visitor = &t{"ll"}
	hi(o)
	hh(o)
}

func hi(v visitor) {
	v.fn(func(v visitor) {
		fmt.Println("ni hao ", v)
	})
}

func hh(v visitor) {
	v.fn(func(v visitor) {
		fmt.Println("haha ", v)
	})
}
